package com.celesea.framework.util;


import com.celesea.framework.authority.User;
import com.celesea.framework.entity.BusEntity;

import java.sql.Date;
import java.util.Calendar;

public class BusUtil {
    /**
     * 自动处理业务属性
     *
     * @param model
     */
    public static void busAuto(BusEntity model) {
        if (StringKit.isEmpty(model.getId())) {
            busCreateInfo(model);
        }
        busUpdateInfo(model);
    }

    /**
     * 业务创建人信息
     */
    public static void busCreateInfo(BusEntity model) {
        User user = EnvUtil.getLoginUser();
        model.setTenantId(EnvUtil.getTenantId());

        model.setCreatorId(user.getId());
        model.setCreatorName(user.getName());
        model.setServerCreateTime(new Date(Calendar.getInstance().getTimeInMillis()));
        model.setDeleteFlag(Const.DeleteFlag.NORMAL);

        busUpdateInfo(model);
    }

    /**
     * 处理业务更新人信息
     */
    public static void busUpdateInfo(BusEntity model) {
        User user = EnvUtil.getLoginUser();
        model.setUpdatorId(user.getId());
        model.setUpdatorName(user.getName());
        model.setServerUpdateTime(new Date(Calendar.getInstance().getTimeInMillis()));
    }

//	/**
//	 * 处理业务查询是的创建人信息
//	 *
//	 * @param queryParam
//	 */
//	public static void busQuery(QueryParam queryParam) {
//		if (queryParam != null) {
//			queryParam.put("createId", UserUtil.getLoginSysUserId());
//		}
//	}
}
